package puzzle.projecteuler.p100;

import astudy.util.AdvMath;
public class Problem027 {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		
		int bound = 999;
		int A = -bound;
		int B = -bound;
		int M = 0;
		for (int a = -bound; a <= bound;  a ++) {
			for (int b = -bound; b <= bound; b ++) {
				int m = length(a, b);
				if (m > M) {
					M = m;
					A = a;
					B = b;
				}
			}
		}
		System.out.println(M);
		System.out.println(A);
		System.out.println(B);
	}

	public static long f(int n, int a, int b) {
		return n*n + a*n + b;
	}
	public static int length(int a, int b) {
		int m = 0;
		for (;;m++) {
			if (!AdvMath.isPrime(Math.abs(f(m,a,b)))) {
				break;
			}
		}
		return m;
	}
}
